from datetime import datetime

from ext import db


class User(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    username = db.Column(db.String(15), nullable=False)
    password = db.Column(db.String(32), nullable=False)
    phone = db.Column(db.String(11), nullable=True, unique=True)
    register_time = db.Column(db.DATETIME, default=datetime.now)

    def __init__(self, username, password, phone=None):
        self.username = username
        self.password = password
        self.phone = phone

"""
#利用这段代码可以生成数据库的表结构
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://root:123456@127.0.0.1:3306/python_template'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_ECHO"] = True
db = SQLAlchemy(app)

if __name__ == '__main__':
    # db.create_all()  # 创建数据表
    u = User("高嘉银", "123456", "18883337187")
    db.session.add(u)
    db.session.commit()
"""
